package com.tarena.lbs.common.basic.converter;


import com.tarena.lbs.pojo.basic.bo.BusinessBO;
import com.tarena.lbs.pojo.basic.dos.BusinessDO;
import com.tarena.lbs.pojo.basic.param.BusinessParam;
import com.tarena.lbs.pojo.basic.vo.BusinessVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Component
public class BusinessConverter {

    public BusinessVO bo2vo(BusinessBO bo) {
        BusinessVO businessVO = new BusinessVO();
        if (null == bo) {
            return null;
        }
        BeanUtils.copyProperties(bo, businessVO);
        return businessVO;
    }

    public BusinessDO param2DO(BusinessParam param) {
        if (null == param) {
            return null;
        }
        BusinessDO businessDO = new BusinessDO();
        BeanUtils.copyProperties(param, businessDO);
        Date now = new Date();

        return businessDO;
    }

    public List<BusinessVO> boListvoList(List<BusinessBO> boList) {
        List<BusinessVO> businessVOS = new ArrayList<>();
        if (CollectionUtils.isEmpty(boList)) {
            return businessVOS;
        }
        for (BusinessBO businessBO : boList) {
            BusinessVO businessVO = new BusinessVO();
            BeanUtils.copyProperties(businessBO, businessVO);
            businessVOS.add(businessVO);
        }
        return businessVOS;
    }


    public List<BusinessBO> doList2boList(List<BusinessDO> doList) {
        List<BusinessBO> boList = new ArrayList<>();
        if (CollectionUtils.isEmpty(doList)) {
            return boList;
        }
        for (BusinessDO businessDO : doList) {
            BusinessBO businessBO = new BusinessBO();
            BeanUtils.copyProperties(businessDO, businessBO);
            boList.add(businessBO);
        }
        return boList;
    }

    public BusinessBO do2bo(BusinessDO businessDO) {
        if (null == businessDO) {
            return null;
        }
        BusinessBO businessBO = new BusinessBO();
        BeanUtils.copyProperties(businessDO, businessBO);
        return businessBO;
    }
}
